package com.keyingbo.leran.spring.framkwork.aop.aspect;

import com.keyingbo.leran.spring.framkwork.aop.intercept.DemoMethodInterceptor;
import com.keyingbo.leran.spring.framkwork.aop.intercept.DemoMethodInvocation;

import java.lang.reflect.Method;
/**
 * @Auther: KEYB
 * @Date: 2019-4-17 14:02
 * @Description:
 */
public class DemoAfterReturningAdviceInterceptor extends DemoAbstractAspectAdvice implements DemoAdvice, DemoMethodInterceptor {

    private DemoJoinPoint joinPoint;

    public DemoAfterReturningAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    @Override
    public Object invoke(DemoMethodInvocation mi) throws Throwable {
        Object retVal = mi.proceed();
        this.joinPoint = mi;
        this.afterReturning(retVal,mi.getMethod(),mi.getArguments(),mi.getThis());
        return retVal;
    }

    private void afterReturning(Object retVal, Method method, Object[] arguments, Object aThis) throws Throwable {
        super.invokeAdviceMethod(this.joinPoint,retVal,null);
    }
}
